package business.inhospitalqc;

import com.alibaba.fastjson.JSONObject;
import com.esotericsoftware.yamlbeans.YamlException;
import common.Data;
import common.RunCaseJson;
import common.Yaml;
import io.restassured.response.Response;
import org.apache.commons.configuration.ConfigurationException;
import org.apache.log4j.Logger;
import utils.GetFileMess;
import utils.YamlReadUtil;

import java.io.FileNotFoundException;
import java.util.HashMap;

import static common.Login.login;

public class CreateTask {
    Logger log = Logger.getLogger(CreateTask.class);
    public static final String system = "env.properties";
    Data data = login();
//    DoctorList doctorList=new DoctorList();
//    BatchGetPatientList batchGetPatientList=new BatchGetPatientList();

    /**
    *
    * @Description: 创建质控任务
     * @param i	api-sourcedata/qc/task/create.json的datas
     * @param ids	api-sourcedata/qc/batch/patient/list.json的datas
     * @param batchId 	api-sourcedata/qc/batch/batchCreate.json的datas
//     * @param l	api-sourcedata/dmp/template/result/list的datas
//     * @param z api-sourcedata/dmp/template/create的datas
     * @return void
    * @author gujinle
    * @date 2021-05-06 18:24
    */
    public void CreateTask(int i,String practitionerId, String ids,String batchId) throws FileNotFoundException, ConfigurationException, YamlException {
//        HashMap hashMap=batchGetPatientList.BatchGetPatientList(j,k,l,z);
//        String practitionerId=doctorList.GetUserList(0);
        String path=new GetFileMess().getValue("ymlPath",system);
        Yaml yaml= YamlReadUtil.getLocatorMap(path,this.getClass().getName());
        JSONObject json = new JSONObject();
        json.put("access_token", data.getAccessToken());
        json.put("authToken", data.getAccessToken());
        json.put("uniqu_no", data.getUniquNo());
        json.put("operatorId", data.getUserId());
        json.put("authUserId", data.getUserId());
        json.put("authName", data.getUserName());
        json.put("qcCheckOption", "6");    //质量管理措施项目 1、急诊记录 2、入院24H内 3、入院72H内 4、治疗72H之后 5、出院前1~2周 6、出院日
        json.put("type", yaml.getDatas().get(i).get("type"));   //1=copd，2=aecopd，3=指标检测图
        json.put("practitionerId", practitionerId);   //从api-users/user/list获取userId
        json.put("batchId", batchId);                  //从/qc/batch/batchCreate.json 获取id
        json.put("ids", ids);    //从/qc/batch/patient/list.json 获取id
        json.put("diseaseCode", yaml.getDatas().get(i).get("diseaseCode"));
        log.info("请求参数：" + json.toString());
        Response response = RunCaseJson.runCase(json, "post", yaml.getUri());
        String jsonStr = response.asString();
        log.info("响应报文：" + jsonStr);

    }


    public static void main(String[] args) throws FileNotFoundException, ConfigurationException, YamlException {
        CreateTask ct=new CreateTask();
//        ct.CreateTask(0,0,0,0,0);

    }
}
